package com.yxw.yx_hotel.controller;

import com.yxw.yx_hotel.dto.QueryRoomReportDto;
import com.yxw.yx_hotel.dto.QueryStayReportDto;
import com.yxw.yx_hotel.service.ReportService;
import com.yxw.yx_hotel.vo.ReportRoomVo;
import com.yxw.yx_hotel.vo.ReportStayVo;
import com.yxw.yx_hotel.vo.ReportTitelVo;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.exception.BaseException;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 *  报表管理
 * @author liuxin
 * @date 2024.01.22
 */
@RestController
@Api(value = "报表管理", tags = "报表管理")
@Slf4j
@RequestMapping("/api/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @ApiOperation(value = "查询宿舍统计列表")
    @PostMapping("/pageRoomReportList")
    public BaseResult<PageVO<ReportRoomVo>> pageRoomReportList(@RequestBody QueryRoomReportDto dto)  {
        PageVO<ReportRoomVo> pageVo=reportService.pageRoomReportList(dto);
        return BaseResult.doSuccess(pageVo,"查询成功");
    }

    @ApiOperation(value = "查询住宿统计列表")
    @PostMapping("/pageStayReportList")
    public BaseResult<PageVO<ReportStayVo>> pageStayReportList(@RequestBody QueryStayReportDto dto)  {
        PageVO<ReportStayVo> pageVo=reportService.pageStayReportList(dto);
        return BaseResult.doSuccess(pageVo,"查询成功");
    }

    @ApiOperation(value = "查询报表标题")
    @GetMapping("/getTitelList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "titelType", value = "1:宿舍标题 2:住宿标题", required = true)
    })
    public BaseResult<List<ReportTitelVo>> getTitelList(@RequestParam Integer titelType)  {
        List<ReportTitelVo> voList=reportService.getTitelList(titelType);
        return BaseResult.doSuccess(voList,"查询成功");
    }

    //----------------------------------------------------------------导入导出------------------------------------------------
    @ApiOperation(value = "宿舍报表数据导出")
    @PostMapping("/exportRoomData")
    public void exportData(HttpServletResponse response, @RequestBody QueryRoomReportDto dto) {
        try {
            reportService.exportRoomData(response,dto);
        }catch (Exception e){
            log.error("导出失败{}",e);
            throw new BaseException(e.getMessage());
        }
    }

    @ApiOperation(value = "住宿报表数据导出")
    @PostMapping("/exportStayData")
    public void exportStayData(HttpServletResponse response, @RequestBody QueryStayReportDto dto) {
        try {
            reportService.exportStayData(response,dto);
        }catch (Exception e){
            log.error("导出失败{}",e);
            throw new BaseException(e.getMessage());
        }
    }
}
